package com.neudu.yiyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neudu.yiyang.mapper.CustomerMapper;
import com.neudu.yiyang.mapper.OutwardMapper;
import com.neudu.yiyang.pojo.Customer;
import com.neudu.yiyang.pojo.Outward;
import com.neudu.yiyang.service.OutwardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OutwardServiceImpl extends ServiceImpl<OutwardMapper, Outward> implements OutwardService {
    @Autowired
    private OutwardMapper outwardMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public Map<String, Object> getOutwardWithCustomerName(Page<Outward> page, String keyword) {
        List<Outward> outwardList = outwardMapper.selectOutwardWithCustomerName(page, keyword);
        Map<String, Object> result = new HashMap<>();
        result.put("pageNum", page.getCurrent());
        result.put("pageSize", page.getSize());
        result.put("total", page.getTotal());
        result.put("list", outwardList);
        return result;
    }
    @Override
    public List<Outward> getOutwardByBedId(Integer bedId) {
        // 根据 bed_id 查询 customer 表获取 customer_id
        Customer customer = customerMapper.getCustomerByBedId(bedId);
        if (customer != null) {
            Integer customerId = customer.getId();
            // 使用 customer_id 查询 outward 表
            return outwardMapper.getOutwardByCustomerId(customerId);
        }
        return null;
    }



}